#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll rr() {
    ll s = 0, w = false, c = getchar();
    for (; !isdigit(c); c = getchar())
        w = w || c == '-';
    for (; isdigit(c); c = getchar())
        s = s * 10 + c - '0';
    return w ? -s : s;
}

// END OF HEADER

int main() {
    int v = rr(), e = rr(), k = rr();
    vector<int> x(e), y(e);
    for (int i = 0; i < e; i++)
        x[i] = rr(), y[i] = rr();
    int n = rr();
    
    while (n--) {
        bool flag = true;
        vector<int> c(v + 1);
        set<int> s;
        for (int i = 1; i <= v; i++) {
            c[i] = rr();
            s.insert(c[i]);
        }
        for (int i = 0; i < e; i++) {
            if (c[x[i]] == c[y[i]])
                flag = false;
        }
        if (flag && s.size() == k)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}
